package cn.fsw.pethome.echarts.controller;

import cn.fsw.pethome.org.domain.po.ShopCO;
import cn.fsw.pethome.org.domain.po.ShopPO;
import cn.fsw.pethome.org.domain.po.ShopVo;
import cn.fsw.pethome.org.service.IShopService;
import cn.fsw.pethome.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/echarts")
public class EchartsController {

    @Autowired
    private IShopService shopService;

    /*根据注册时间统计店铺注册数量*/
    @GetMapping("/chartLine")
    public AjaxResult chartLine(){
        List<ShopPO> shopPOS = shopService.chartLine();
        return AjaxResult.ajaxResult().setData(shopPOS);
    }
    /*按照状态统计店铺数量*/
    @GetMapping("/chartColumn")
    public List<Integer> chartColumn(){
        List<ShopVo> shopVos = shopService.chartColumn();
        List<Integer> collect = shopVos.stream().map(ShopVo::getCountNum).collect(Collectors.toList());
        return collect;
    }

    /*根据地址统计店铺数量*/
    @GetMapping("/chartBar")
    public AjaxResult chartBar(){
        List<ShopCO> shopCOS = shopService.chartBar();
        List<Integer> collect = shopCOS.stream().map(ShopCO::getCountNum).collect(Collectors.toList());
        List<String> address = shopCOS.stream().map(ShopCO::getAddress).collect(Collectors.toList());
        Map<String,Object> result = new HashMap<>();
        result.put("collect",collect);
        result.put("address",address);
        return AjaxResult.ajaxResult().setData(result);
    }
}
